<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__CSS__/layui.css"  media="all">
	<script src="__UI__/layui.js"></script>

	<script src="__PUBLIC__/js/jquery.js"></script>

	<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body class="layui-layout-body" style="overflow: auto">
<div class="layui-layout layui-layout-admin">
	<div style="padding: 15px;">
	<div class="layui-row">
		<div class="layui-col-xs3">
			<div class="layui-btn-group">
				<!--  <button class="layui-btn" data-type="search">搜索</button> -->
				<button class="layui-btn layui-btn-warm" data-url="{:url('add')}" onclick="add_t(this,'添加测试')">
					添加测试
				</button>
			</div>
		</div>
	</div>
	<table class="layui-table"
		   lay-data="{width:'auto', height:'auto', url:'{:url('ceshi/index')}', page: true, limit: 10, id:'test'}"
		   lay-filter="test">
		<thead>
		<tr>
	 		<th lay-data="{checkbox:true, fixed: true}"></th>
			<th lay-data="{field:'name', width:370,  sort: true}">问题名称</th>
			<th lay-data="{field:'question_user', width:150,  sort: true}">发布者</th>
			<th lay-data="{field:'question_time', width:170,  sort: true}">发布时间</th>
			<th lay-data="{field:'answer_user', width:150, sort: true}">修改者</th>
			<th lay-data="{field:'answer_time', width:170, sort: true}">修改时间</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:290, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
   </div>
</div>
	<script type="text/html" id="barDemo">
		{{# if(d.status == 1){ }}
		<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="" style="width: 80px">已结束</a>
		{{# }else{ }}
		<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="" style="width: 80px">未结束</a>
		{{# } }}
		<a class="layui-btn layui-btn-sm" data-url="{:url('edit','id=')}{{d.id}}" onclick="add_t(this,'编辑测试')"  style="width: 70px">查看</a>
		<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="del" style="width: 70px">删除</a>
	</script>
	<script>
		layui.use('table', function () {
			var table = layui.table;
			//监听工具条
			table.on('tool(test)', function (obj) {
				var id = obj.data.id;
				if (obj.event == 'del') {
					layer.confirm('确定删除吗?', {icon: 3, title:'提示'}, function(index){
						$.post("{:url('index/apilist_del')}",{"id":id},function(res){
							if(res.code == 0){
								layer.close(index);
								location.reload();
							}	
						},'json')
					  
					});
				}
				if (obj.event == 'edit') {
					location = "{:url('ceshi/edit','id=')}"+id;
						// $.post("{:url('ceshi/edit')}",{"id":id},function(res){
						// 	if(res.code == 0){
						// 		layer.close(index);
						// 		location.reload();
						// 	}	
						// },'json')
				}
			});

			//监听排序
			table.on('sort(test)', function (obj) {

			});

		});
		layui.use('laydate', function () {
			var laydate = layui.laydate;

			//墨绿主题
			laydate.render({
				elem: '#test6-1' //指定元素
				, type: 'datetime'
				, theme: 'molv'
				//,range: true
				, trigger: 'click'
			});

			laydate.render({
				elem: '#test6-2' //指定元素
				, type: 'datetime'
				, theme: 'molv'
				//,range: true
				, trigger: 'click'
			});

		});
	</script>

</body>
<script>
	function add_t(obj,title){
		var url = $(obj).data('url');
		var index = layui.layer.open({
			title : title,
			type : 2,
			content : url,
			success : function(layero, index){
				setTimeout(function(){
					layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
						tips: 3,
						time:3000
					});
				},500)
			}
		})
		//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
		$(window).resize(function(){
			layui.layer.full(index);
		})
		layui.layer.full(index);
	}
   // layer = parent.layer,
   // layer.closeAll("iframe");
</script>
</html>
